<?php

namespace App\Policies;

use App\Models\Bar;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class BarPolicy
{
    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return true; // 所有人都可以查看贴吧列表
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, Bar $bar): bool
    {
        return true; // 所有人都可以查看贴吧详情
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
        return true; // 已登录用户都可以创建贴吧
    }

    /**
     * Determine whether the user can update the model.
     */
    public function update(User $user, Bar $bar): bool
    {
        // 只有吧主可以更新贴吧信息
        return $bar->isOwner($user);
    }

    /**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, Bar $bar): bool
    {
        // 只有吧主或全局管理员可以删除贴吧
        return $bar->isOwner($user) || $user->isAdmin();
    }

    /**
     * Determine whether the user can restore the model.
     */
    public function restore(User $user, Bar $bar): bool
    {
        //
    }

    /**
     * Determine whether the user can permanently delete the model.
     */
    public function forceDelete(User $user, Bar $bar): bool
    {
        //
    }
}
